<include file="Public/head" />
<link type="text/css" rel="stylesheet" href="{:get_style_cdnurl()}paimai/yunying/plugin/select2/select2.css" />
<script src="{:get_style_cdnurl()}paimai/yunying/plugin/select2/select2.js" type="text/javascript"></script>
<style type="text/css">
    .loan_1,.loan_2{display: block;height:25px;width: 100%;}
    .loan_1{margin-top: 10px;}
    .loan_2{float:left;}
    .text_model{
        border: 1px solid #d7d7d7;  float: left;  height: 24px; line-height: 24px;  margin: 0 10px 10px 0;  text-align: center;  width: 150px;
    }
    .search_btn{height:26px;line-height:26px;
        background: #20ab4f none repeat scroll 0 0;border-radius: 3px;border:medium none;
        margin-left: 7px;padding: 0;width: 60px;float:left;}
    .select_model{
        -moz-appearance: none;background: rgba(0, 0, 0, 0) url("{:get_style_cdnurl()}paimai/yunying/images/sanjiao.jpg") no-repeat scroll 115px 5px;
        border: 1px solid #d7d7d7;
        float: left;height: 26px;line-height: 26px;margin-right: 8px;text-indent: 2px;width: 136px;}
    /*#start_time,#end_time{border: 1px solid #d7d7d7;height: 24px;line-height: 24px;text-align: center;float: left;}*/
    #end_time{margin-left: 10px;}

    .tanShang .daiJingW{padding: 20px 0 0 50px;}
    .tanShang6 .cardealer-zhanghao{width:560px;}
    .tanShang6{height:300px;}
    .tanShang6 .cardealer-zhanghao{height:30px; line-height:30px;margin:0; text-align:left; overflow:hidden;}
    .tanShang6 .cardealer-zhanghao span{width:120px; text-align:right;float:left; display:block;}
    .tanShang6 .cardealer-zhanghao em{color:#20ab4f;padding:0;font-size:14px;}
</style>
</head>
<include file="Public/common_header" />
<div class="mian">
    <include file="Public/sidebar"  menu="cwgl.dksk" />
    <div class="mianR">
        <div class="yuyue">
            <ul>
                <li onclick="get_list(1)" class="yuCurrent">待通知放款</li>
                <li onclick="get_list(2)">待放款</li>
                <li onclick="get_list(3)">已放款</li>
                <li onclick="get_list(4)">收款成功</li>
            </ul>
        </div>

        <div class="yuSuo clearfix">
            <div class="loan_1">
                <input id="status" name="status" type="hidden" value="{$params.status}"/>
                <input type="text" id="loan_no" name="loan_no" placeholder="贷款编号" value="{$params.lano_no}" class="text_model" />
                <input type="text" id="order_no" name="order_no" placeholder="拍单编号" value="{$params.order_no}" class="text_model" />
                <select name="location_area" id="location_area" class="select_model">
                    <if condition="count($bc_city) gt 1">
                        <option value="0">请选择所在地</option>
                    </if>
                    <volist name="bc_city" id="city">
                        <option value="{$key}">{$city}</option>
                    </volist>
                </select>
                <input type="text" id="contact_person" name="contact_person" value="{$params.contact_person}"  placeholder="请输入车商联系人"  class="text_model">
                <input type="text" id="contact_mobile" name="contact_mobile" value="{$params.contact_mobile}"  placeholder="请输入联系电话"  class="text_model">
            </div>
            <div class="loan_2">
                <input type="text" name="start_time" placeholder="过户开始时间" value=""  id="start_time" readonly>
                <input type="text" name="end_time"  placeholder="过户结束时间" value=""  id="end_time" readonly />
                <input type="button" id="search_btn" value="搜索" class="search_btn" style="color: #FFF;">
            </div>
        </div>

        <div class="yunList">
            <div class="listBox" id="listBox">

            </div>
        </div>
    </div>
    <div class="clear"></div>
    <div class="yunBei loan_money_dialog" style="display:none"></div>
    <form id="add_fm">
        <div class="tanShang tanShang6 add_tanShang" style="display:none">
            <h3>确认放款</h3>
            <ul class="daiJingW">
                <li class="cardealer-zhanghao">
                    <span>
                        贷款编号：
                    </span>
                    <em id="loan_num"></em>
                </li>
                <li class="cardealer-zhanghao">
                    <span>
                        贷款申请金额：
                    </span>
                    <em id="loan_money"></em>
                </li>
                <li class="cardealer-zhanghao">
                    <span>
                        拍单编号：
                    </span>
                    <em id="order_num"></em>
                </li>
                <li class="cardealer-zhanghao">
                    <span>
                        车型：
                    </span>
                    <em id="car_model"></em>
                </li>
                <li class="cardealer-zhanghao">
                    <span>
                        车商联系人：
                    </span>
                    <em id="dealer_contact_person"></em>
                </li>
                <li class="clearfix" style="height: 30px;line-height: 30px;padding-left: 56px;margin-bottom: 10px;">
                    确认以上贷款放款已经到账？
                </li>
                <li class="clearfix">
                    <input type="hidden" name="xm_id">
                    <input type="hidden" name="order_id">
                    <input type="button" value="确定" class="queding" id="qd_loan_money"/>
                    <input type="button" value="取消" class="quxiao" />
                </li>
            </ul>
        </div>
    </form>
</div>
    <include file="Public/foot" />

    <script type="text/javascript">
        $("#start_time").ymdateplugin({
//            showTimePanel: true,
//            changeMonth: true,
//            changeYear: true
        });
        $("#end_time").ymdateplugin({
//            showTimePanel: true,
//            changeMonth: true,
//            changeYear: true
        });


        function get_page(p){
            var status = $("#status").val();
            var url = get_url();
            url += "&p=" + p;
            if(status == 1){
                var requestUrl = '/LoanReceiveble/notransfer_loan_list';
            }else{
                var requestUrl = '/LoanReceiveble/loan_list';
            }
            $.get(requestUrl+ "?status=" + status, encodeURI(url), function(data){
                $("#listBox").html(data);
            },"html");
        }
        get_list(1);
        function get_list(status){
            change_tabs(status);
            $("#status").val(status);
            var url = get_url();
            if(status == 1){
               var requestUrl = '/LoanReceiveble/notransfer_loan_list';
            }else{
               var requestUrl = '/LoanReceiveble/loan_list';
            }
            $.get(requestUrl+ "?status=" + status, url, function(data){
                $("#listBox").html(data);
            },"html");
        }

        function get_url(){
            var url = "";
            var location_area = $("#location_area").val();
            var loan_no = $("#loan_no").val();
            var order_no = $("#order_no").val();
            var contact_person = $("#contact_person").val();
            var contact_mobile = $("#contact_mobile").val();
            var start_time = $("#start_time").val();
            var end_time = $("#end_time").val();
            if (location_area > 0) {
                url += '&location_area=' + location_area;
            }
            if (loan_no) {
                url += '&loan_no=' + loan_no;
            }
            if (order_no) {
                url += '&order_no=' + order_no;
            }
            if (contact_person) {
                url += '&contact_person=' + contact_person;
            }
            if (contact_mobile) {
                url += '&contact_mobile=' + contact_mobile;
            }
            if (start_time) {
                url += '&start_time=' + start_time;
            }
            if (end_time) {
                url += '&end_time=' + end_time;
            }
            return url;
        }

        $('#search_btn').on('click',function(){
            var status = $("#status").val();
            get_list(status);
        });

        /**
         * 核实
         * @param xm_id
         * @param order_id
         */
        function loan_verify(xm_id, order_id){
            $.post('/LoanReceiveble/get_loan_info', {'xm_id': xm_id}, function (data) {
                $("#loan_num").html(data.xm_list_code);
                $("#loan_money").html(data.loan_money);
                $("#order_num").html(data.order_no);
                $("#car_model").html(data.car_model);
                $("#dealer_contact_person").html(data.contact_person);
                $("input[name='xm_id']").val(xm_id);
                $("input[name='order_id']").val(order_id);
                $('.loan_money_dialog,.add_tanShang').show();
            }, 'json');
        }

        /**
         * 确定核实
         */
        $("#qd_loan_money").on("click", function () {
            xm_id = $("input[name='xm_id']").val();
            order_id = $("input[name='order_id']").val();
            post_data = {
                'xm_id': xm_id,
                'order_id' : order_id
            }
            var btn_obj = $(this);
            btn_obj.val("提交中...").attr("disabled", 'disabled');
            $.post("/LoanReceiveble/loan_verify", post_data, function (data) {
                try {
                    if (data.code == 200) {
                        btn_alert('放款成功!', 300);
                        setTimeout(function () {
                            btn_obj.val("确定").removeAttr("disabled style");
                            window.location.reload();
                        }, 400);
                    } else {
                        btn_obj.val("确定").removeAttr("disabled style");
                        shibai_alert(data.msg, 300);
                    }
                } catch (e) {
                    btn_obj.val("确定").removeAttr("disabled style");
                    shibai_alert('放款失败!', 300);
                }
            }, 'json');
        });

        function change_tabs(status){
            if(status == 1) {
                $('#start_time').attr('placeholder','申请开始时间');
                $('#end_time').attr('placeholder','申请结束时间');
            }else if(status == 2){
                $('#start_time').attr('placeholder','过户开始时间');
                $('#end_time').attr('placeholder','过户结束时间');
            }else if(status == 3){
                $('#start_time').attr('placeholder','放款开始时间');
                $('#end_time').attr('placeholder','放款结束时间');
            }else if(status == 4){
                $('#start_time').attr('placeholder','收款开始时间');
                $('#end_time').attr('placeholder','收款结束时间');
            }
            if($("#status").val() != status){
                clear_form_params();
            }
        }
        function clear_form_params(){
            $(':input')
                    .not(':button, :submit, :reset, :hidden, select')
                    .val('');
        }
    </script>